<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客系统 - 分类管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- 导航栏省略 -->

<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>分类管理</h2>
        <a href="${pageContext.request.contextPath}/category?action=add" class="btn btn-primary">
            <i class="bi bi-plus-circle"></i> 添加分类
        </a>
    </div>

    <c:if test="${not empty errorMsg}">
        <div class="alert alert-danger">${errorMsg}</div>
    </c:if>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>分类名称</th>
                        <th>描述</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:choose>
                        <c:when test="${not empty categoryList}">
                            <c:forEach items="${categoryList}" var="category">
                                <tr>
                                    <td>${category.id}</td>
                                    <td>${category.name}</td>
                                    <td>${category.description}</td>
                                    <td>
                                        <a href="${pageContext.request.contextPath}/category?action=edit&id=${category.id}"
                                           class="btn btn-sm btn-outline-primary">编辑</a>
                                        <a href="${pageContext.request.contextPath}/category?action=delete&id=${category.id}"
                                           class="btn btn-sm btn-outline-danger"
                                           onclick="return confirm('确定要删除该分类吗？此操作会同时删除该分类下的所有文章！')">删除</a>
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:when>
                        <c:otherwise>
                            <tr>
                                <td colspan="4" class="text-center">暂无分类，请添加分类</td>
                            </tr>
                        </c:otherwise>
                    </c:choose>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
</body>
</html>